home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / thesrc10.zip / EDIT.C < prev    next >
C/C++ Source or Header  |  1992-08-04  |  8KB  |  232 lines

  1. /***********************************************************************/
  2. /* EDIT.C - The body of the program.                                   */
  3. /***********************************************************************/
  4. /*
  5.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  6.  * Copyright (C) 1991,1992 Mark Hessling
  7.  * 
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License as
  10.  * published by the Free Software Foundation; either version 2 of
  11.  * the License, or any later version.
  12.  * 
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16.  * General Public License for more details.
  17.  * 
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to:
  20.  * 
  21.  *    The Free Software Foundation, Inc.
  22.  *    675 Mass Ave,
  23.  *    Cambridge, MA 02139 USA.
  24.  * 
  25.  * 
  26.  * If you make modifications to this software that you feel increases
  27.  * it usefulness for the rest of the community, please email the
  28.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  29.  * This software is going to be maintained and enhanced as deemed 
  30.  * necessary by the community.
  31.  *
  32.  * Mark Hessling                     email: M.Hessling@itc.gu.edu.au
  33.  * 36 David Road                     Phone: +61 7 849 7731
  34.  * Holland Park                      Fax:   +61 7 875 7877
  35.  * QLD 4121
  36.  * Australia
  37.  */
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <time.h>
  41.  
  42. #include "the.h"
  43.  
  44. /*#define TRACE*/
  45. /*-------------------------- external data ----------------------------*/
  46. extern LINE *next_line,*curr_line;
  47. extern VIEW_DETAILS *vd_current,*vd_first;
  48. extern char current_file;         /* pointer to current file */
  49. extern char number_of_views;                   /* number of open files */
  50. extern char current_screen;
  51. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  52. extern WINDOW *foot,*error_window;
  53. extern char error_on_screen;
  54. extern unsigned char *rec;
  55. extern unsigned short rec_len;
  56. extern unsigned char *cmd_rec;
  57. extern unsigned short cmd_rec_len;
  58. extern unsigned char mode_insert;        /* defines insert mode toggle */
  59. extern char file_disposition;
  60. extern short file_start;
  61. extern unsigned char *dirfilename;
  62. /*---------------------- function definitions -------------------------*/
  63. #ifdef PROTO
  64. void show_heading(int);
  65. void show_footing(void);
  66. int function_key(int);
  67. char case_translate(char);
  68. #else
  69. void show_heading();
  70. void show_footing();
  71. int function_key();
  72. char case_translate();
  73. #endif
  74. /***********************************************************************/
  75. #ifdef PROTO
  76. void editor(void)
  77. #else
  78. void editor()
  79. #endif
  80. /***********************************************************************/
  81. {
  82. /*--------------------------- local data ------------------------------*/
  83.  short key=0;
  84.  char real_key;
  85.  unsigned short x,y;
  86.  int rc;
  87. /*--------------------------- processing ------------------------------*/
  88. #ifdef TRACE
  89.  trace_function("edit.c:    editor");
  90. #endif
  91.  show_page();
  92.  show_heading(key);
  93.  show_footing();
  94.  if (CURRENT_VIEW->prefix_on)
  95.     wnoutrefresh(CURRENT_WINDOW_PREFIX);
  96.  if (strcmp(CURRENT_FILE->fname,dirfilename) == 0)
  97.     wmove(CURRENT_WINDOW_MAIN,CURRENT_VIEW->current_row,file_start-1);
  98.  else
  99.     wmove(CURRENT_WINDOW_MAIN,CURRENT_VIEW->current_row,0);
  100.  
  101.  wnoutrefresh(CURRENT_WINDOW_MAIN);
  102.  wmove(CURRENT_WINDOW_COMMAND,0,0);
  103.  wnoutrefresh(CURRENT_WINDOW_COMMAND);
  104.  if (file_disposition != FILE_NORMAL)
  105.    {
  106.     switch(file_disposition)
  107.       {
  108.        case FILE_NEW:
  109.                           display_error(0,"New File...");
  110.                           break;
  111.        case FILE_READONLY:
  112.                           display_error(0,"File is read-only...");
  113.                           break;
  114.        default:
  115.                           break;
  116.       }
  117.     touchwin(error_window);
  118.     wnoutrefresh(error_window);
  119.     wrefresh(CURRENT_WINDOW);
  120.    }
  121.  doupdate();
  122.  
  123.  while (1)
  124.   {
  125.    key = my_getch(CURRENT_WINDOW);
  126.    if (error_on_screen == YES)
  127.       {
  128.        error_on_screen = NO;
  129.        touchwin(foot);
  130.       }
  131.    rc = function_key(key);
  132.    if (rc == QUIT && number_of_views == 0)
  133.        break;
  134.    if (rc >= RAW_KEY)
  135.      {
  136.       if (rc > RAW_KEY)
  137.         key = rc - (RAW_KEY*2);
  138.       if (key < 256 && key >= 0)
  139.         {
  140.          real_key = case_translate((char)key);
  141.          switch(CURRENT_VIEW->current_window)
  142.            {
  143.             case WINDOW_MAIN:
  144.                  if (CURRENT_VIEW->focus_line == 0
  145.                  ||  CURRENT_VIEW->focus_line == CURRENT_FILE->number_lines + 1)
  146.                     break;
  147.                  getyx(CURRENT_WINDOW,y,x);
  148.                  if (mode_insert)
  149.                    {
  150.                     rec = (unsigned char *)meminschr((char *)rec,
  151.                                     real_key,CURRENT_VIEW->verify_col-1+x,
  152.                                     MAX_LINE_LENGTH,rec_len);
  153.                     put_char(CURRENT_WINDOW,real_key,INSCHAR);
  154.                    }
  155.                  else
  156.                    {
  157.                     rec[CURRENT_VIEW->verify_col-1+x] = real_key;
  158.                     if (x == CURRENT_SCREEN.cols-1)
  159.                       {
  160.                        put_char(CURRENT_WINDOW,real_key,INSCHAR);
  161.                       }
  162.                     else
  163.                        put_char(CURRENT_WINDOW,real_key,ADDCHAR);
  164.                    }
  165.                  rc = memrevne(rec,' ',MAX_LINE_LENGTH);
  166.                  if (rc == (-1))
  167.                     rec_len = 0;
  168.                  else
  169.                     rec_len = rc+1;
  170.                  /* this is done here so that the show_page() in */
  171.                  /* Right_arrow() is executed AFTER we get the   */
  172.                  /* new length of rec_len.                       */
  173.                  if (mode_insert
  174.                  || x == CURRENT_SCREEN.cols-1)
  175.                     Right_arrow("");
  176.                  break;
  177.             case WINDOW_COMMAND:
  178.                  getyx(CURRENT_WINDOW,y,x);
  179.                  if (mode_insert)
  180.                    {
  181.                     cmd_rec = (unsigned char *)meminschr((char *)cmd_rec,
  182.                                     real_key,x,
  183.                                     COLS,cmd_rec_len);
  184.                     put_char(CURRENT_WINDOW,real_key,INSCHAR);
  185.                     Right_arrow("");
  186.                    }
  187.                  else
  188.                    {
  189.                     cmd_rec[x] = real_key;
  190.                     put_char(CURRENT_WINDOW,real_key,ADDCHAR);
  191.                    }
  192.                  rc = memrevne(cmd_rec,' ',COLS);
  193.                  if (rc == (-1))
  194.                     cmd_rec_len = 0;
  195.                  else
  196.                     cmd_rec_len = rc+1;
  197.                  break;
  198.             case WINDOW_PREFIX:
  199.                  wclrtoeol(CURRENT_WINDOW);
  200.                  if (mode_insert)
  201.                    {
  202.                     put_char(CURRENT_WINDOW,real_key,INSCHAR);
  203.                     Right_arrow("");
  204.                    }
  205.                  else
  206.                     put_char(CURRENT_WINDOW,real_key,ADDCHAR);
  207.                  break;
  208.            }
  209.         }
  210.      }
  211.    wnoutrefresh(CURRENT_WINDOW_MAIN);
  212.    if (CURRENT_VIEW->prefix_on)
  213.       wnoutrefresh(CURRENT_WINDOW_PREFIX);
  214.    wnoutrefresh(CURRENT_WINDOW_COMMAND);
  215.    show_heading(real_key);
  216.    show_footing();
  217.  
  218.    wnoutrefresh(CURRENT_WINDOW);
  219.    doupdate();
  220.    if (error_on_screen == YES)
  221.       {
  222.        touchwin(error_window);
  223.        wnoutrefresh(error_window);
  224.        wrefresh(CURRENT_WINDOW);
  225.       }
  226.  }
  227. #ifdef TRACE
  228.  trace_return();
  229. #endif
  230.  return;
  231. }
  232.